package com.yunsc.admin.controller.order;

import com.yunsc.common.utils.PageResult;
import com.yunsc.common.utils.Result;
import com.yunsc.common.utils.SecurityUtil;
import com.yunsc.common.validator.ValidationGroups;
import com.yunsc.order.dto.OrderRefundDTO;
import com.yunsc.order.dto.QueryOrderRefundDTO;
import com.yunsc.order.sevice.YunscOrderRefundService;
import com.yunsc.order.vo.OrderRefundVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @version: 1.0
 * @Author: adan
 * @description: 订单售后接口
 * @date: 2024-01-24 16:46
 */
@Api(value = "订单售后接口", tags = "订单信息接口")
@Slf4j
@RestController
@RequestMapping("order/refund")
public class OrderRefundController {

    @Resource
    private YunscOrderRefundService orderRefundService;

    @ApiOperation(value = "订单售后列表", notes = "订单售后列表")
    @GetMapping("/list")
    public Result<?> queryRefundOrder(QueryOrderRefundDTO orderRefundDTO) {
        // 根据dataType和page获取用戶订单列表数据
        Integer currentStoreId = SecurityUtil.getCurrentStoreId();
        PageResult<OrderRefundVO> refundOrder = orderRefundService.queryRefundOrders(orderRefundDTO, currentStoreId);
        return Result.resultPageList(refundOrder);
    }

    @GetMapping("/detail")
    public Result<?>  queryOrderRefundDetail(@RequestParam("orderRefundId") Integer orderRefundId){
        OrderRefundVO refundOrder = orderRefundService.queryRefundOrderDetail(orderRefundId);
        Map<String, Object> map = new HashMap<>();
        map.put("detail", refundOrder);
        return Result.ok(map);
    }


    @PostMapping("/audit")
    public Result<?> auditOrderRefund(@RequestBody @Validated(ValidationGroups.Update.class) OrderRefundDTO param) {
        orderRefundService.auditOrderRefund(param);
        return Result.ok("审核成功");
    }

}
